package cn.cau.epidemicsurveysystem.control;
import cn.cau.epidemicsurveysystem.bean.KnowledgeBean;
import cn.cau.epidemicsurveysystem.service.KnowledgeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class WechatKnowledgeController {
    @Autowired
    KnowledgeService knowledgeService;
    //小程序-获取全部知识
    @RequestMapping(value = "/wechatKnowledgeList",method = RequestMethod.GET)
    public List<Map<String, Object>> getWechatKnowledgeList(){
        List<Map<String, Object>> knowledgeList= new ArrayList<Map<String, Object>>();
        List<KnowledgeBean> knowledgeBeans=knowledgeService.getAllKnowledge();
        for (KnowledgeBean knowledgeBean : knowledgeBeans) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("knowledgeId",knowledgeBean.getKnowledgeId());
            map.put("knowledgeTitle",knowledgeBean.getKnowledgeTitle());
            knowledgeList.add(map);
        }
        return knowledgeList;
    }
    //小程序-请求知识库详情
    @RequestMapping(value = "/wechatKnowledgeDetail",method = RequestMethod.GET)
    public KnowledgeBean getWechatKnowledgeDetail(@RequestParam("knowledgeId") String knowledgeId){
        return knowledgeService.getKnowledgeById(Integer.valueOf(knowledgeId));
    }
}
